Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GHSA-gmj6-6f8f-6699] Jinja has a sandbox breakout through malicious filenames #5150

Conversation

frenzymadness
Copy link

Updates

  • Affected products
  • CVSS v3
  • Description

Comments
Jinja2 before the release 3.0.0a1 didn't use f-strings for the error message which means version 2 should not be vulnerable.

The code in the vulnerable release 3.4.1 is:

            message = (
                "the template {included_template.__name__!r}"
                f" (imported on {self.position(node)})"
                f" does not export the requested name {name!r}"
            )

so if the content of self.position(node) is something like {bad}, it might then be interpreted as an f-string.

However, the code in the latest 2.11.3 is:

            self.writeline(
                "%s = undefined(%r %% "
                "included_template.__name__, "
                "name=%r)"
                % (
                    frame.symbols.ref(alias),
                    "the template %%r (imported on %s) does "
                    "not export the requested name %s"
                    % (self.position(node), repr(name)),
                    name,
                )
            )

Which means that if the self.position(node) contains something with % like %sbad%s, it results in TypeError: not enough arguments for format string because in the old-style formatting, there is no way to access variables by their names or run a code.

@github
Copy link
Collaborator

github commented Jan 8, 2025

Hi there @davidism! A community member has suggested an improvement to your security advisory. If approved, this change will affect the global advisory listed at github.com/advisories. It will not affect the version listed in your project repository.

This change will be reviewed by our Security Curation Team. If you have thoughts or feedback, please share them in a comment here! If this PR has already been closed, you can start a new community contribution for this advisory

@github-actions github-actions bot changed the base branch from main to frenzymadness/advisory-improvement-5150 January 8, 2025 13:33
@@ -29,7 +25,7 @@
"type": "ECOSYSTEM",
"events": [
{
"introduced": "0"
"introduced": "3.0.0a1"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't bother with alpha versions here, just use 3.0.0.

"published": "2024-12-23T17:54:12Z",
"aliases": [
"CVE-2024-56201"
],
"summary": "Jinja has a sandbox breakout through malicious filenames",
"details": "A bug in the Jinja compiler allows an attacker that controls both the content and filename of a template to execute arbitrary Python code, regardless of if Jinja's sandbox is used.\n\nTo exploit the vulnerability, an attacker needs to control both the filename and the contents of a template. Whether that is the case depends on the type of application using Jinja. This vulnerability impacts users of applications which execute untrusted templates where the template author can also choose the template filename.",
"details": "A bug in the Jinja compiler allows an attacker that controls both the content and filename of a template to execute arbitrary Python code, regardless of if Jinja's sandbox is used.\n\nTo exploit the vulnerability, an attacker needs to control both the filename and the contents of a template. Whether that is the case depends on the type of application using Jinja. This vulnerability impacts users of applications which execute untrusted templates where the template author can also choose the template filename.\n\nJinja before 3.0.0a1 is not vulnerable as it does not use f-strings for formatting error messages.",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't include version information here, it's already explained by the version information fields.

@advisory-database advisory-database bot merged commit 948059d into frenzymadness/advisory-improvement-5150 Jan 8, 2025
2 checks passed
@advisory-database
Copy link
Contributor

Hi @frenzymadness! Thank you so much for contributing to the GitHub Advisory Database. This database is free, open, and accessible to all, and it's people like you who make it great. Thanks for choosing to help others. We hope you send in more contributions in the future!

@advisory-database advisory-database bot deleted the frenzymadness-GHSA-gmj6-6f8f-6699 branch January 8, 2025 16:06
@shelbyc
Copy link
Contributor

shelbyc commented Jan 8, 2025

Thank you @frenzymadness and @davidism for the clarification on which versions are affected. I've updated GHSA-gmj6-6f8f-6699 and the CVE record for CVE-2024-56201 to indicate that only 3.x versions are vulnerable. https://www.cve.org/CVERecord?id=CVE-2024-56201 has the current information but it will take some time for the updated information to propagate to https://nvd.nist.gov/vuln/detail/CVE-2024-56201.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants